/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.bme.j2ee.v37zen.beans;

import hu.bme.j2ee.v37zen.entities.User;
import hu.bme.j2ee.v37zen.util.Role;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Kiss Dániel
 */
@Stateless
@LocalBean
public class RegisterUserBean {

    @PersistenceContext
    EntityManager em;
    
    
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    public void registerUser(User user) {
        em.persist(user);
    }
    
    public User createUser(final String username, final String email, final String password) {
        User user = new User(username, email, password);
        em.persist(user);
        return user;
    }

    public User createAdministrator(final String username, final String email, final String password) {
        User user = createUser(username, email, password);
        user.setRoles(Role.SET_of_USDER_AND_ADMIN);
        return user;
    }
    
    
    
}
